package cn.book.service.impl;

import cn.book.dao.BookQueryMapper;
import cn.book.entity.BookQuery;
import cn.book.service.BookQueryService;
import cn.book.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class BookQueryServiceImpl implements BookQueryService {

    @Override
    public List<BookQuery> getBookPage(String bookName, String bookAuthor, String bookType, Integer pageIndex, Integer pageSize) {
        SqlSession sqlSession = null;
        List<BookQuery> bookList = null;
        try {
            sqlSession = MyBatisUtil.createSqlSession();
            bookList = sqlSession.getMapper(BookQueryMapper.class).getBookPage(bookName, bookAuthor, bookType, pageIndex, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
        return bookList ;
    }

    @Override
    public Integer getTotalBook(String bookName, String bookAuthor,String bookType) {
        SqlSession sqlSession = null;
        Integer count = null;
        try {
            sqlSession = MyBatisUtil.createSqlSession();
            count = sqlSession.getMapper(BookQueryMapper.class).getTotalBook(bookName, bookAuthor, bookType);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
        return count ;
    }

}